package com.gragra.util.tests;
import static org.junit.Assert.*;
import org.junit.Test;
import com.gragra.sampling.ThreadedUniformAccess;
import com.gragra.util.BooleanInterweave;
public class TestBooleanInterweave
{
	/**
	 * 
	 */
	private final short[] scorners = new short[] {0,-1,Short.MAX_VALUE,Short.MIN_VALUE};
	/**
	 * 
	 */
	private final int[] corners = new int[] {0,-1,Integer.MAX_VALUE,Integer.MIN_VALUE};
	/**
	 * 
	 */
	private ThreadedUniformAccess tua = new ThreadedUniformAccess(1);
	@Test
	public void testGetFirstLong()
	{
		for(int i : corners)
		{
			for(int j : corners)
			{assertEquals(i,BooleanInterweave.getFirst(BooleanInterweave.combine(i, j)));}
		}
		for(int i=0;i<1000000;++i)
		{
			int one = tua.nextInt(0);
			int two = tua.nextInt(0);
			assertEquals(one,BooleanInterweave.getFirst(BooleanInterweave.combine(one, two)));
		}
	}
	@Test
	public void testGetSecondLong()
	{
		for(int i : corners)
		{
			for(int j : corners)
			{assertEquals(j,BooleanInterweave.getSecond(BooleanInterweave.combine(i, j)));}
		}
		for(int i=0;i<1000000;++i)
		{
			int one = tua.nextInt(0);
			int two = tua.nextInt(0);
			assertEquals(two,BooleanInterweave.getSecond(BooleanInterweave.combine(one, two)));
		}
	}
	@Test
	public void testGetFirstInt()
	{
		for(int i=0;i<1000000;++i)
		{
			short one = (short) tua.nextInt(0);
			short two = (short) tua.nextInt(0);
			assertEquals(one,BooleanInterweave.getFirst(BooleanInterweave.combine(one, two)));
		}
		for(short i : scorners)
		{
			for(short j : scorners)
			{assertEquals(i,BooleanInterweave.getFirst(BooleanInterweave.combine(i, j)));}
		}
	}
	@Test
	public void testGetSecondInt()
	{
		for(short i : scorners)
		{
			for(short j : scorners)
			{assertEquals(j,BooleanInterweave.getSecond(BooleanInterweave.combine(i, j)));}
		}
		for(int i=0;i<1000000;++i)
		{
			short one = (short) tua.nextInt(0);
			short two = (short) tua.nextInt(0);
			assertEquals(two,BooleanInterweave.getSecond(BooleanInterweave.combine(one, two)));
		}
	}
}